﻿using System;
using System.Collections.Generic;
using System.Text;
using FeCMS.Entity.AccessControlModule;
using FeCMS.CommonFunction;

namespace FeCMS.AccessControlModule.handle
{
    /// <summary>
    ///     角色的操作
    /// </summary>
    internal class RoleHandle : BaseHandle<Role, int>
    {
        public RoleHandle(Dictionary<int, Role> obj)
            : base(obj)
        { 

        }


        public override int Add(Role e)
        {
            int id = SetDelegateGetIndex(HandleType.Role);
            //修改ID与权限排序
            e.ID = id;
            Algorithm.QuickSort(e.Permission, 0, e.Permission.Length-1);
            if (Add(id, e))
            {
                return id;
            }
            else
            {
                return -1;
            }
        }

        public override bool Edit(int i, Role e)
        {
            //修改ID与权限排序
            e.ID = i;
            Algorithm.QuickSort(e.Permission, 0, e.Permission.Length - 1);
            return base.Edit(i, e);
        }
    }
}
